const db = require("../config/db");

// 获取所有提现记录
exports.getAll = async () => {
  const [rows] = await db.query(
    "SELECT id, phone, merchant_name AS merchantName, receiver, bankAccount, bankName, amount, create_time AS createTime, status FROM cash ORDER BY id DESC"
  );
  return rows;
};

// 根据ID获取提现记录
exports.getById = async (id) => {
  const [rows] = await db.query(
    "SELECT id, phone, merchant_name AS merchantName, receiver, bankAccount, bankName, amount, create_time AS createTime, status FROM cash WHERE id = ?",
    [id]
  );
  return rows[0];
};

// 更新提现状态为已打款
exports.updateStatus = async (id) => {
  await db.query("UPDATE cash SET status = 'paid' WHERE id = ?", [id]);
  return true;
};
